<?php

namespace Biz\model\MijiaSmartKitchen;

use Biz\pockets\modelTrait\BizModelTrait;
use Doraemon\pockets\datebase\BaseDbModel;

class MiJiaSmartKitchenUserLottery extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_brand_activity';

    const _DATABASE_ = 'brand_activity';

    const _TABLE_NAME = 'mijia_smart_kitchen_user_lottery';

    const WINNING_YES = 1; //中奖
    const WINNING_NO = 0;  //未中奖

    const LOTTERY_PLATFORM_WECHAT = 1;

    use BizModelTrait;


    /**
     * @desc 添加一条抽奖记录
     * @param $uid
     * @param $did
     * @param $uip
     * @param $lotteryTime
     * @param $thirdId
     * @param $lotteryPlatform
     * @param $winning
     * @return false|int
     */
    public static function add($uid, $did, $uip, $lotteryTime, $thirdId, $lotteryPlatform, $winning = self::WINNING_NO)
    {
        $data = [
            'uid' => $uid,
            'device_id' => $did,
            'uip' => $uip,
            'third_id' => $thirdId,
            'lottery_platform' => $lotteryPlatform,
            'lottery_time' => $lotteryTime,
            'winning' => $winning,
            'create_time' => date('Y-m-d H:i:s', time()),
            'update_time' => date('Y-m-d H:i:s', time()),
        ];
        return self::dataInsert($data);
    }

    /**
     * 用户是否已抽奖
     * @param $uniq_uid
     * @param $platform
     * @return bool
     */
    public static function hasUserLottery($uniq_uid, $platform)
    {

        if ($platform == self::LOTTERY_PLATFORM_WECHAT) {
            $uid = 0;
            $third_id = $uniq_uid;
            $lottery_latform = 1;
        } else {
            $uid = $uniq_uid;
            $third_id = '';
            $lottery_latform = 0;
        }

        $where['uid'] = $uid;

        $where['third_id'] = $third_id;

        $where['lottery_platform'] = $lottery_latform;

        return self::dataHas($where);
    }

}